
import {history, post, message, get} from '@/utils/utils'

const changeFee = {
  namespaced: true,
  state: {
  },

  mutations: {
  },

  actions: {
    updateFee({ commit, dispatch }, {newRate, type, modifyMno, agentNo}) {
      const body = {
        newRate
      }

      if (type === 'default') {
        body.modifyType = '1'
        body.agentNo = agentNo
      } else {
        body.modifyType = '3'
        body.agentNo = agentNo
        body.modifyMno = modifyMno
      }

      post({api: '/agt/agentratemodify/mofiyRate',
        data: body,
        success: (data) => {
          if (type === 'default') {
            commit('home/save', {field: 'agentInfo', payload: {directMerchantRate: newRate}}, {root: true})
          } else {
            commit('managementDetail/save', {field: 'detail', payload: {rate: newRate}}, {root: true})
          }

          message.success('提交成功')
          setTimeout(() => history.goBack(), 1500)
        }})
    }
  }
}

export default changeFee
